<script type="text/javascript">
    $(function(){
        $('button.btn').click(function(e){
            var buttons = $(this).parent().find('button');
            for(var i=0; i <= buttons.length;i++)
            {
                $(buttons[i]).attr('class','btn btn-default');
            }
            if($(this).attr('id') === 'publish'){
                $(this).attr('class','btn btn-success');
            }
            else if($(this).attr('id') === 'no_publish'){
                $(this).attr('class','btn btn-danger');
            }
            else if($(this).attr('id') === 'trash'){
                $(this).attr('class','btn btn-warning');
            }

        });
       $('.form').find('input:last').click(function(e){
           var hostname = location.hostname;
           var protocol = location.protocol;
           document.location.replace(protocol+'//'+hostname+'/menu/backend/admin');

        });
    });
</script>
<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl.'/js/form-validator.js',CClientScript::POS_HEAD)?>
<?php
/* @var $this BackendController */
/* @var $model Menu */
/* @var $form CActiveForm */
?>

<div class="form">

<?php $form=$this->beginWidget('TActiveForm', array(
	'id'=>'menu-form',
    'method'=>'post',
	// Please note: When you enable ajax validation, make sure the corresponding
	// controller action is handling ajax validation correctly.
	// There is a call to performAjaxValidation() commented in generated controller code.
	// See class documentation of CActiveForm for details on this.
    'enableAjaxValidation'=>true,
    'enableClientValidation'=>true,
    'clientOptions'=>array(
        'afterValidate'=>'js:afterValidate',
        'validateOnSubmit'=>true,
        'validateOnType'=>true,
        'validateOnChange'=>true,
        'hideErrorMessage'=>true
    ),
)); ?>
    <div class="alert alert-info">
	    <p class="note"><?php echo Yii::t('MenuModule.base','Fields with')?> <span class="required">*</span> <?php echo Yii::t('MenuModule.base','are required.')?></p>
    </div>

    <div class="btn-group">
        <button type="button" id = "publish" class="btn btn-default">Опубликованно</button>
        <button type="button" id = "no_publish" class="btn btn-default">Не опубликованно</button>
        <button type="button" id = "trash" class="btn btn-default">В корзине</button>
    </div>

    <div class="well well-sm">
        <?php echo $form->labelEx($model,'submenu'); ?>
        <?php echo $form->dropDownList($model,'submenu',$model->getSubMenuOptions()); ?>
        <?php echo $form->error($model,'submenu',array('afterValidateAttribute'=>'js:afterValidateAttribute')); ?>
        <span class="well-into">
            <?php echo $form->labelEx($model,'position'); ?>
            <?php echo $form->dropDownList($model,'position',$model->getPositionOptions()); ?>
            <?php echo $form->error($model,'position'); ?>
        </span>
        <span class="well-into">
            <?php echo $form->labelEx($model,'module'); ?>
            <?php echo $form->dropDownList($model,'module',$model->getModulesOptions()); ?>
            <?php echo $form->error($model,'module',array('afterValidateAttribute'=>'js:afterValidateAttribute')); ?>
        </span>

         <span class="well-into">
            <?php echo $form->labelEx($model,'hidden'); ?>
            <?php echo $form->dropDownList($model,'hidden',$model->getHiddenOptions()); ?>
            <?php echo $form->error($model,'hidden',array('afterValidateAttribute'=>'js:afterValidateAttribute')); ?>
         </span>
    </div>

    <div class="input-group">
        <?php echo $form->labelTb($model,'item_name',array('style'=>'width:150px')); ?>
        <?php echo $form->textFieldTb($model,'item_name',array('size'=>50,'maxlength'=>255)); ?>
        <?php echo $form->error($model,'item_name',array('afterValidateAttribute'=>'js:afterValidateAttribute')); ?>
    </div>

    <div class="input-group">
        <?php echo $form->labelTb($model,'title',array('style'=>'width:150px')); ?>
        <?php echo $form->textFieldTb($model,'title',array('size'=>50,'maxlength'=>255)); ?>
        <?php echo $form->error($model,'title',array('afterValidateAttribute'=>'js:afterValidateAttribute')); ?>
    </div>

    <div class="input-group">
        <?php echo $form->labelTb($model,'description',array('style'=>'width:150px')); ?>
        <?php echo $form->textFieldTb($model,'description',array('size'=>50,'maxlength'=>255)); ?>
        <?php echo $form->error($model,'description',array('afterValidateAttribute'=>'js:afterValidateAttribute')); ?>
    </div>

    <div class="input-group">
        <?php echo $form->labelTb($model,'link_path',array('style'=>'width:150px')); ?>
        <?php echo $form->textFieldTb($model,'link_path',array('size'=>50,'maxlength'=>255)); ?>
        <?php echo $form->error($model,'link_path',array('afterValidateAttribute'=>'js:afterValidateAttribute')); ?>
    </div>

    <div class="input-group">
        <?php echo $form->labelTb($model,'link_title',array('style'=>'width:150px')); ?>
        <?php echo $form->textFieldTb($model,'link_title',array('size'=>50,'maxlength'=>255)); ?>
        <?php echo $form->error($model,'link_title',array('afterValidateAttribute'=>'js:afterValidateAttribute')); ?>
    </div>

    <div class="well well-sm">
        <?php echo $form->labelEx($model,'body_format'); ?>
        <?php echo $form->dropDownList($model,'body_format',$model->getBodyFormatOptions()); ?>
        <?php echo $form->error($model,'body_format'); ?>

        <span class="well-into">
            <?php echo $form->labelEx($model,'pages_count'); ?>
            <?php echo $form->dropDownList($model,'pages_count',$model->getPagesCountOptions()); ?>
            <?php echo $form->error($model,'pages_count'); ?>
        </span>
    </div>

	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? Yii::t('MenuModule.base','Create') : Yii::t('MenuModule.base','Save'),array('class'=>'btn btn-default')); ?>
        <?php echo CHtml::button(Yii::t('MenuModule.base','Cancel'),array('class'=>'btn btn-default')); ?>
	</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
